#!/usr/bin/env python
try:
    import json
except:
    from helper import HelpJson as json
import sys
import class_set
import helper


class FeedMapper(helper.MapperHelper):
    """
    from feed.log
    get contentid\ttag(which is review)
    """

    def loader(self, line):
        try:
            line = line.strip()
            node_operator = json.loads(line)
            contentid = node_operator['contentid']
            tp = node_operator['type']
            addtime = node_operator['addtime']
            tag = class_set.RecomTagFeed(tp)
            tag.setTime(addtime)
            tag.setRelatedId(contentid)
            if tp == 'review':
                return (contentid, tag)
            else:
                return (None, None)
        except:
            return (None, None)

    def mapper(self):
        for line in sys.stdin:
            left, right = self.loader(line)
            if left is not None:
                self.allocator(left, right)


def main():
    fm = FeedMapper()
    fm.mapper()
    
    

if __name__ == '__main__':
    main()
